<template>
    <div class="app-container">
        <el-card>
            <el-table :data="tableData" v-loading="loading" stripe style="width: 100%"
                :header-cell-style="headerStyle"
                :cell-style="cellStyle"
            >
                <el-table-column prop="ct" label="时间" min-width="180">
                    <template #default="scope">
                        {{moment(scope.row.ct).format('yyyy-MM-DD HH:mm:ss')}}
                    </template>
                </el-table-column>
                <el-table-column prop="projectName" label="项目名称" min-width="180">
                    <template #default="scope">
                        {{scope.row.projectName || '--'}}
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="文件名称" min-width="180"/>
                <el-table-column prop="size" label="状态" min-width="180">
                    <template #default="scope">
                        <el-tag :type="downloadStatus[scope.row.state].type">{{downloadStatus[scope.row.state].text}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="progress" label="操作" width="120">
                    <template #default="scope">
                        <el-button type="primary" link :disabled="scope.row.state != 'Success'" :loading="scope.row.loading" @click="handleDownload(scope.row)" >打开</el-button>
                    </template>
                </el-table-column>                
            </el-table>
        </el-card>
    </div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { DownloadQuery, DownloadFile } from "@/api/user";
import moment from 'moment';
import { downloadStatus } from "@/utils/static";
import { ElMessage } from 'element-plus';
import { openFile } from "@/api/user";
const tableData = ref([]);
const loading = ref(false);
onMounted(() => {
    getDownloadData();
});
const getDownloadData = async () => {
    loading.value = true;
    const res = await DownloadQuery();
    loading.value = false;
    if(res.errorCode == 0){
        tableData.value = res.data;
    }
}
const handleDownload = async (row) => {
    // window.open(row.url);
    row.loading = true;
    let result = await openFile({path:row.path});
    row.loading = false;

}
</script>

<style scoped lang="scss">

</style>